package com.morizhang.merchanmanager.api.bean;

import java.util.HashMap;
import java.util.Map;

public class StatisticDataHolder {
    private static Map<String, Boolean> dataExpire = new HashMap<>();
    private static Map<String, Object> dataHolder = new HashMap<>();

    public static void setNewData(String name, Object data) {
        if (dataHolder.containsKey(name)) {
            dataHolder.replace(name, data);
            dataExpire.replace(name, true);
            return;
        }
        dataHolder.put(name, data);
        dataExpire.put(name, true);
    }

    public static void makeExpire(String name) {
        if (! dataHolder.containsKey(name))
            return;
        dataExpire.replace(name, false);
    }

    public static boolean checkExpire(String name) {
        if (! dataExpire.containsKey(name))
            return false;
        return dataExpire.get(name);
    }

    public static Object getData(String name) {
        if (dataHolder.containsKey(name))
            return dataHolder.get(name);
        return null;
    }
}